package com.platform.service;

import com.platform.dao.ApiUserAuthMapper;
import com.platform.entity.UserAuthVo;
import com.platform.oss.OSSFactory;
import com.platform.utils.RRException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ApiUserAuthService {
    @Autowired
    private ApiUserAuthMapper userAuthDao;
    public void save(UserAuthVo userAuthVo) {
        userAuthDao.save(userAuthVo);
    }
    public void deleteByUserId(Long user_id) {
        try {
            List<UserAuthVo> userAuthVos = userAuthDao.queryByUserId(user_id);
            if(userAuthVos==null||userAuthVos.size()==0){return;}
            UserAuthVo userAuthVo=userAuthVos.get(0);
            OSSFactory.build().delete(userAuthVo.getIdcardimgz());
            OSSFactory.build().delete(userAuthVo.getIdcardimgf());
            OSSFactory.build().delete(userAuthVo.getPermitimg());
            OSSFactory.build().delete(userAuthVo.getShopimg());
            userAuthDao.delete(userAuthVo.getId());
        } catch (Exception e) {
            throw new RRException("删除旧认证信息失败");
        }
    }
}
